package com.neu.wangxiaoyang.servlet;

import com.alibaba.fastjson.JSONObject;
import com.neu.wangxiaoyang.service.QueryDorNoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet(name = "FindDorNoServlet", urlPatterns = {"/FindDorNoServlet.do"})
public class FindDorNoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            String build=request.getParameter("dor_build");
        System.out.println(build);
            List<Map<String ,Object >>list=null;
        QueryDorNoService qs=new QueryDorNoService();
        list=qs.findByBuild(build);
        for(Object obj:list){
            System.out.println(obj);
        }
        String str="";
        if(list.size()>0){
            str=JSONObject.toJSONString(list);
        }

        PrintWriter out=response.getWriter();
//        因为前段获取数据时指明了数据的格式为Json
//        所以后天返回时数据必须是Json格式
        out.write(str);
        out.close();

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
